#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;

int n, res;
int a[N], col[N];

void fre()
{
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
}

void dfs(int steps)
{
    if (steps == n + 1)
    {
        int cnt = 0;
        int s0 = 0, s1 = 0;
        for (int i = 1; i <= n; i ++ )
        {
            if (col[i] == 0)
            {
                if (s0 && s0 == a[i]) cnt += a[i];
                s0 = a[i];
            }
            if (col[i] == 1)
            {
                if (s1 && s1 == a[i]) cnt += a[i];
                s1 = a[i];
            }
        }
        res = max(res, cnt);
        return;
    }

    col[steps] = 1;
    dfs(steps + 1);

    col[steps] = 0;
    dfs(steps + 1);
}

int main()
{
	fre();
	int T; cin >> T;
	while (T -- )
	{
		cin >> n;
		for (int i = 1; i <= n; i ++ )
            cin >> a[i];
        
        res = 0;
        if (n <= 30)
        {
            dfs(1);
            cout << res << endl;
        }
        else cout << 0 << endl;
	}
	return 0;
}
